package com.ct.gd.passport.view.passport;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TableRow;
import android.widget.TextView;

import com.ct.gd.passport.R;
import com.ct.gd.passport.common.BaseActivity;
import com.ct.gd.passport.common.constants.Config;
import com.ct.gd.passport.common.constants.Config.Area;
import com.ct.gd.passport.common.constants.UmengVar;
import com.ct.gd.passport.common.util.StringUtils;
import com.ct.gd.passport.domain.PassportApplyResult;
import com.ct.gd.passport.domain.PassportGoApply;
import com.ct.gd.passport.domain.PassportInfo;
import com.ct.gd.passport.service.PassportService;
import com.umeng.analytics.MobclickAgent;
import com.up91.common.android.async.ILoading;
import com.up91.common.android.async.SimpleAsyncTask;
import com.up91.common.android.helper.L;
import com.up91.common.android.helper.ToastHelper;

public class PassportApp2Activity extends BaseActivity implements View.OnClickListener, OnCheckedChangeListener,
		OnItemSelectedListener {

	Spinner mSprArea;
	EditText mEtPassId;
	Button mBtnPassDate;
	Button mBtnBirthday;
	EditText mEtName;
	EditText mEtPhotoNumber;
	RadioButton mRbHongKong;
	RadioButton mRbMacao;
	Spinner mSprValidityHK;
	Spinner mSprValidityMC;
	Button mBtnPre;
	Button mBtnConfirm;
	Spinner mSprGoArea;
	Spinner mSprGoType;
	ImageView mIvValidate;

	CheckBox mCbNeedExpress;
	TableRow mTrSmsSjr;
	TableRow mTrSmsAddr;
	TableRow mTrSmsYb;
	EditText mEtSmsSjr;
	EditText mEtSmsAddr;
	EditText mEtSmsYb;

	TableRow mTrValidate;
	TextView mTvValidate;
	EditText mEtValidate;

	// PopupWindow mPwPassDate;
	// PopupWindow mPwBirthday;

	PassportGoApply mPassportApply;

	ArrayAdapter mAdapterHKType;
	ArrayAdapter mAdapterMACType;

	Dialog mDlgValidate;
	Dialog mDlgBirthday;
	
	Dialog shutdownDlg;

	@Override
	protected void onBaseCreate(Bundle savedInstanceState) {
		setContentView(R.layout.passport_app_2);
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
	}

	@Override
	protected void initViews() {
		mSprArea = (Spinner) findViewById(R.id.grly_spr_area);
		mEtPassId = (EditText) findViewById(R.id.grly_et_pass);
		mBtnPassDate = (Button) findViewById(R.id.grly_btn_passdate);
		mBtnBirthday = (Button) findViewById(R.id.grly_btn_birthday);
		mEtName = (EditText) findViewById(R.id.grly_et_name);
		mEtPhotoNumber = (EditText) findViewById(R.id.grly_et_phonenumber);
		mRbHongKong = (RadioButton) findViewById(R.id.grly_rb_hongkong);
		mRbMacao = (RadioButton) findViewById(R.id.grly_rb_macao);
		mSprValidityHK = (Spinner) findViewById(R.id.grly_spr_hktype);
		mSprValidityMC = (Spinner) findViewById(R.id.grly_spr_mctype);
		mBtnPre = (Button) findViewById(R.id.btn_app2_pre);
		mBtnConfirm = (Button) findViewById(R.id.btn_app2_confirm);
		mSprGoArea = (Spinner) findViewById(R.id.grly_spr_goarea);
		mSprGoType = (Spinner) findViewById(R.id.grly_spr_gotype);
		mIvValidate = (ImageView) findViewById(R.id.grly_iv_validateImg);

		mCbNeedExpress = (CheckBox) findViewById(R.id.grly_cb_needexpress);
		mTrSmsSjr = (TableRow) findViewById(R.id.grly_tb_emssjr);
		mTrSmsAddr = (TableRow) findViewById(R.id.grly_tb_emsaddr);
		mTrSmsYb = (TableRow) findViewById(R.id.grly_tb_emsyb);
		mEtSmsSjr = (EditText) findViewById(R.id.grly_et_emssjr);
		mEtSmsAddr = (EditText) findViewById(R.id.grly_et_emsaddr);
		mEtSmsYb = (EditText) findViewById(R.id.grly_et_emsyb);

		mTrValidate = (TableRow) findViewById(R.id.grly_tr_validate);
		mTvValidate = (TextView) findViewById(R.id.grly_tv_validate);
		mEtValidate = (EditText) findViewById(R.id.grly_et_validate);

		mCbNeedExpress.setOnCheckedChangeListener(this);
		mCbNeedExpress.setChecked(true);

		ArrayAdapter adapterArea = ArrayAdapter.createFromResource(this, R.array.GRLY_AREAS,
				android.R.layout.simple_spinner_item);
		adapterArea.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		mSprArea.setAdapter(adapterArea);

		// ArrayAdapter adapterHKType = ArrayAdapter.createFromResource(this,
		// R.array.GRLY_APPLYHK_TYPES,
		// android.R.layout.simple_spinner_item);
		// adapterHKType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// mSprValidityHK.setAdapter(adapterHKType);
		//
		// ArrayAdapter adapterMCType = ArrayAdapter.createFromResource(this,
		// R.array.GRLY_APPLYMC_TYPES,
		// android.R.layout.simple_spinner_item);
		// adapterMCType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		// mSprValidityMC.setAdapter(adapterMCType);

		ArrayAdapter adapterGoArea = ArrayAdapter.createFromResource(this, R.array.GRLY_APPLY_GOAREA,
				android.R.layout.simple_spinner_item);
		adapterGoArea.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		mSprGoArea.setAdapter(adapterGoArea);

		mAdapterHKType = ArrayAdapter.createFromResource(this, R.array.GRLY_APPLYHK_TYPES,
				android.R.layout.simple_spinner_item);
		mAdapterHKType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		mAdapterMACType = ArrayAdapter.createFromResource(this, R.array.GRLY_APPLYMC_TYPES,
				android.R.layout.simple_spinner_item);
		mAdapterMACType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

		mSprGoType.setAdapter(mAdapterHKType);
		mSprGoArea.setOnItemSelectedListener(this);

		mBtnPassDate.setOnClickListener(this);
		mBtnBirthday.setOnClickListener(this);
		mBtnPre.setOnClickListener(this);
		mBtnConfirm.setOnClickListener(this);

		mRbHongKong.setOnCheckedChangeListener(this);
		mRbMacao.setOnCheckedChangeListener(this);

		// debug code
		// CacheBuilder<String, PassportGoApply> cacheBuilder = new
		// CacheBuilder<String, PassportGoApply>()adapterArea;
		// cacheBuilder.setType(CacheBuilder.CacheType.DEFAULT_L2).setCacheName(name)

		// for (int i = 0; i < 10; i++) {
		// apply = getFormApply();
		// apply.setSerial("" + i);
		// PassportRecordFacade.instance.addPassportRecord(apply);
		// }
	}

	@Override
	protected void onAfterCreate(Bundle savedInstanceStat) {
		Intent intent = getIntent();
		mPassportApply = null;
		if (intent != null) {
			// 重新提交时
			// String id = intent.getStringExtra("number");
			// PassportGoApply apply =
			// PassportRecordFacade.instance.getPassportGoApply(id);
			PassportGoApply apply = intent.getParcelableExtra("goapply");
			if (apply != null) {
				setFormApply(apply);
				mPassportApply = apply;
				new CheckFormTask(this, true).execute(apply);
			}
		}
//		showDebugDialog();
	}
	
	/**
	 * 弹出退出程序的对话框
	 */
	public final void showDebugDialog() {
		if (null == shutdownDlg) {
			shutdownDlg = new AlertDialog.Builder(this).setTitle("使用测试数据测试功能吗?")
					.setPositiveButton("确定", new DialogInterface.OnClickListener() {

						public void onClick(DialogInterface dialog, int which) {
							Config.PASSPORT_TEST = true;
							if (Config.PASSPORT_TEST) {
								PassportGoApply apply = new PassportGoApply();
//								apply.setPassportId("W28868996");
								apply.setPassportId("W47003648");
//								apply.setPassLimitDate("2013-12-07");
								apply.setPassLimitDate("2016-03-23");
								apply.setBirthday("1965-12-19");
//								apply.setBirthday("1975-06-17");

//								apply.setName("屈健强");
								apply.setName("何惠燕");
//								apply.setPhoneNumber("13928858116");
								apply.setPhoneNumber("13378643747");
								apply.setEmsName("何惠燕");
//								apply.setEmsName("屈健强");
								apply.setEmsAddr("佛山市禅城区惺台公38号");
								apply.setPostCord("528000");
								setFormApply(apply);
							}
						}
					}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
						public void onClick(DialogInterface dialog, int which) {
							Config.PASSPORT_TEST = false;
							shutdownDlg.dismiss();
						}
					}).create();
		}
		shutdownDlg.show();
	}

	// @Override
	// protected void onBaseCreate(Bundle savedInstanceState) {
	//
	// }
	//
	// @Override
	// protected void initViews() {
	//
	// }

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.grly_btn_passdate:
			// if (mPwPassDate == null) {
			// mPwPassDate = makePopupWindow(mBtnPassDate);
			// }
			// if (mPwPassDate != null) {
			// mPwPassDate.showAsDropDown(v, 0, 12);
			// }
			if (mDlgValidate != null) {
				mDlgValidate.show();
			} else {
				mDlgValidate = makePopupWindow(mBtnPassDate, mBtnPassDate.getText().toString());
			}
			break;
		case R.id.grly_btn_birthday:
			// if (mPwBirthday == null) {
			// mPwBirthday = makePopupWindow(mBtnBirthday);
			// }
			// if (mPwBirthday != null) {
			// mPwBirthday.showAsDropDown(v, 0, 12);
			// }
			if (mDlgBirthday != null) {
				mDlgBirthday.show();
			} else {
				mDlgBirthday = makePopupWindow(mBtnBirthday, mBtnBirthday.getText().toString());
			}
			break;
		case R.id.btn_app2_confirm:
			if(validate() == false){
				return;
			}
			if (mTrValidate.getVisibility() != View.VISIBLE) {
				mPassportApply = getFormApply();
			}
			if (mPassportApply != null) {
				// new SubmitPassportTask(this, true).execute(mPassportApply);
				if (mTrValidate.getVisibility() != View.VISIBLE) {
					new CheckFormTask(this, true).execute();
				} else {
					// 检查验证码
					// ...
					// 提交验证码
					mPassportApply.setValidateCode(mEtValidate.getText().toString());
					new SendDataAndValidateCode(this, true).execute();
				}
			}
			break;
		case R.id.btn_app2_pre:
			Intent intentPre = new Intent(this, PassportApp1Activity.class);
			startActivity(intentPre);
			finish();
			break;
		}
	}
	
	private boolean validate(){
		if(org.apache.commons.lang3.StringUtils.isBlank(mEtPassId.getText().toString())){
			ToastHelper.toast(this, "请输入通行证号码");
			return false;
		}
		if(org.apache.commons.lang3.StringUtils.isBlank(mBtnPassDate.getText().toString())){
			ToastHelper.toast(this, "请选择通行证有效期");
			return false;
		}
		if(org.apache.commons.lang3.StringUtils.isBlank(mEtName.getText().toString())){
			ToastHelper.toast(this, "请输入姓名");
			return false;
		}
		if(org.apache.commons.lang3.StringUtils.isBlank(mEtPhotoNumber.getText().toString())){
			ToastHelper.toast(this, "请输入联系电话");
			return false;
		}
		if(org.apache.commons.lang3.StringUtils.isBlank(mEtSmsSjr.getText().toString())){
			ToastHelper.toast(this, "请输入收件人");
			return false;
		}
		if(org.apache.commons.lang3.StringUtils.isBlank(mEtSmsAddr.getText().toString())){
			ToastHelper.toast(this, "请输入速递地址");
			return false;
		}
		if(org.apache.commons.lang3.StringUtils.isBlank(mEtSmsYb.getText().toString())){
			ToastHelper.toast(this, "请输入邮政编码");
			return false;
		}
		return true;
	}

	// 创建一个包含自定义view的PopupWindow
	private AlertDialog makePopupWindow(final Button btnDate, String date) {
		// final PopupWindow window = new PopupWindow(LayoutParams.WRAP_CONTENT,
		// LayoutParams.WRAP_CONTENT);

		LinearLayout view = new LinearLayout(this);
		view.setOrientation(LinearLayout.VERTICAL);
		final DatePicker dp = new DatePicker(this);
		// Button btn = new Button(this);
		// btn.setText("确定");
		view.addView(dp);
		// view.addView(btn);
		view.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
		// view.setBackgroundResource(R.drawable.tr_form_bg);

		if (!TextUtils.isEmpty(date)) {
			int[] args = StringUtils.getDateFromStringToInt(date);
			if (args != null && args[1] > 0) {
				dp.init(args[0], args[1] - 1, args[2], null);
			}
		}

		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setView(view).setTitle("选择日期").setPositiveButton("确定", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				btnDate.setText(dp.getYear() + "-" + StringUtils.getIntString(dp.getMonth() + 1, 2) + "-"
						+ StringUtils.getIntString(dp.getDayOfMonth(), 2));
			}
		});
		AlertDialog dlg = builder.create();
		dlg.show();

		// btn.setOnClickListener(new OnClickListener() {
		// public void onClick(View v) {
		// btnDate.setText(dp.getYear() + "-" + (dp.getMonth() + 1) + "-" +
		// dp.getDayOfMonth());
		// window.dismiss();
		// }
		// });
		//
		// window.setContentView(view);
		// // 设置PopupWindow外部区域是否可触摸
		// window.setOutsideTouchable(true);
		// window.setFocusable(true);
		// window.setBackgroundDrawable(new BitmapDrawable());
		// return window;
		return dlg;
	}

	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		switch (buttonView.getId()) {
		case R.id.grly_rb_hongkong:
			if (isChecked) {
				mRbMacao.setChecked(false);
			}
			break;
		case R.id.grly_rb_macao:
			if (isChecked) {
				mRbHongKong.setChecked(false);
			}
			break;
		case R.id.grly_cb_needexpress:
			// int visibility = isChecked ? View.VISIBLE : View.GONE;
			// mTrSmsSjr.setVisibility(visibility);
			// mTrSmsAddr.setVisibility(visibility);
			// mTrSmsYb.setVisibility(visibility);
			ToastHelper.toast(this, R.string.passport_submit_only_express_tip);
			break;
		}
	}

	private void showValidate(Drawable img) {
		mTrValidate.setVisibility(View.VISIBLE);
		mIvValidate.setImageDrawable(img);
		mEtValidate.setText("");
		mEtValidate.requestFocus();
	}

	private void hideValidate() {
		mTrValidate.setVisibility(View.GONE);
	}

	/**
	 * by test
	 * 
	 * @param apply
	 */
	public void setFormApply(PassportGoApply apply) {
		if (apply != null) {
			try {
				mEtPassId.setText(apply.getPassportId());
				mBtnBirthday.setText(apply.getBirthday());
				mBtnPassDate.setText(apply.getPassLimitDate());
				mEtName.setText(apply.getName());
				mEtPhotoNumber.setText(apply.getPhoneNumber());
				
				mEtSmsAddr.setText(apply.getEmsAddr());
				mEtSmsSjr.setText(apply.getEmsName());
				mEtSmsYb.setText(apply.getPostCord());

				// 更多的设置

			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}

	public PassportGoApply getFormApply() {
		String aPassportId = mEtPassId.getText().toString();
		String aPassLimitDate = mBtnPassDate.getText().toString();
		String aBirthdaty = mBtnBirthday.getText().toString();
		String aName = mEtName.getText().toString();
		String aPhoneNumber = mEtPhotoNumber.getText().toString();
		String aEmsName = mEtSmsSjr.getText().toString();
		String aEmsAddr = mEtSmsAddr.getText().toString();
		String aPostCord = mEtSmsYb.getText().toString();
		if (TextUtils.isEmpty(aPassportId) || TextUtils.isEmpty(aPassLimitDate) || TextUtils.isEmpty(aBirthdaty)
				|| TextUtils.isEmpty(aName) || TextUtils.isEmpty(aPhoneNumber)
				|| TextUtils.isEmpty(aEmsName)
				|| TextUtils.isEmpty(aEmsAddr)
				|| TextUtils.isEmpty(aPostCord)
		// || TextUtils.isEmpty(aEmsName)
		// || TextUtils.isEmpty(aEmsAddr)
		// || TextUtils.isEmpty(aPostCord)
		) {
			ToastHelper.toastLong(this, "请将表单填写完整再提交。");
			return null;
		}

		PassportGoApply goApply = new PassportGoApply();
		String[] arrAreaValue = getResources().getStringArray(R.array.GRLY_AREAS_VALUE);
		goApply.setAreaValue(arrAreaValue[mSprArea.getSelectedItemPosition()]);
		//转大写
		goApply.setPassportId(mEtPassId.getText().toString().toUpperCase());
		mEtPassId.setText(mEtPassId.getText().toString().toUpperCase());
		goApply.setPassLimitDate(mBtnPassDate.getText().toString());
		goApply.setBirthday(mBtnBirthday.getText().toString());
		goApply.setName(mEtName.getText().toString());
		goApply.setPhoneNumber(mEtPhotoNumber.getText().toString());
		goApply.setEms(mCbNeedExpress.isChecked());
		if (mCbNeedExpress.isChecked()) {
			//114前缀
			if(mEtSmsSjr.getText().toString().indexOf("114")<0){
				goApply.setEmsName("114"+mEtSmsSjr.getText().toString());
				mEtSmsSjr.setText("114"+mEtSmsSjr.getText().toString());
			}
			goApply.setEmsAddr(mEtSmsAddr.getText().toString());
			goApply.setPostCord(mEtSmsYb.getText().toString());
		}
		String[] arrHKTypeValue = getResources().getStringArray(R.array.GRLY_APPLYHK_TYPE_VALUE);
		String[] arrMCTypeValue = getResources().getStringArray(R.array.GRLY_APPLYMC_TYPE_VALUE);

		int areaPosition = mSprGoArea.getSelectedItemPosition();
		int typePosition = mSprGoType.getSelectedItemPosition();
		// String[] AREAS = {"HKG","MAC"};
		Area[] AREAS = { Area.HKG, Area.MAC };
		String[][] VALUES = { arrHKTypeValue, arrMCTypeValue };
		goApply.setArea(AREAS[areaPosition]);
		goApply.setGoType(VALUES[areaPosition][typePosition]);
		goApply.setUnderWrite(mEtName.getText().toString());
		return goApply;
	}

	@Override
	public void onItemSelected(AdapterView<?> av, View v, int position, long arg3) {
		switch (av.getId()) {
		case R.id.grly_spr_goarea:
			mSprGoType.setAdapter(position != 0 ? mAdapterMACType : mAdapterHKType);
			break;
		}
	}

	@Override
	public void onNothingSelected(AdapterView<?> arg0) {
		// TODO Auto-generated method stub

	}

	public class SubmitPassportTask extends SimpleAsyncTask<PassportGoApply, Void, PassportApplyResult> {

		public SubmitPassportTask(ILoading loading, boolean showLoading) {
			super(loading, showLoading);
		}

		@Override
		protected PassportApplyResult onLoad(PassportGoApply... params) throws Exception {
			return PassportApplyResult.load(params[0]);
		}

		@Override
		protected void onUI(PassportApplyResult result) {
			if (result != null) {
				String info = "您的申请已初步受理(尚未审批)，受理编号为: " + result.getId();
				Intent intentConfirm = new Intent(getContext(), PassportAppFinishActivity.class);
				intentConfirm.putExtra("result", info);
				startActivity(intentConfirm);
				finish();
			} else {
				ToastHelper.toast(getContext(), "提交失败，请重试");
			}
		}

	}

	/**
	 * 通过passportid获取个人信息 检测姓名、生日、通行证到期时间三项，来验证用户合法性
	 * 
	 * @author Twinkle
	 * 
	 */
	public class CheckFormTask extends SimpleAsyncTask<PassportGoApply, Integer, PassportInfo> {
		public CheckFormTask(ILoading loading, boolean showLoading) {
			super(loading, showLoading);
		}

		@Override
		protected PassportInfo onLoad(PassportGoApply... params) throws Exception {
			return PassportService.loadPassport(mPassportApply.getPassportId());
		}

		@Override
		protected void onUI(PassportInfo result) {
			
			if (result == null || result.getId() == null) {
				// 提示证件号码无效
				ToastHelper.toast(getContext(), "该通信证信息无法获取，请在检查后重试或稍后再试");
				return;
			}
			L.e("info", "edt:"+mPassportApply.getBirthday()+"|formResult:"+result.getBirthDate());
			StringBuffer tip = new StringBuffer();
			if (mPassportApply.getBirthday() == null || !mPassportApply.getBirthday().equals(result.getBirthDate())) {
				tip.append("出生日期与通行证上不符！\n");
			}
			if (mPassportApply.getPassLimitDate() == null
					|| !mPassportApply.getPassLimitDate().equals(result.getPassLimitDate())) {
				tip.append("通行证有效期与通行证上不符！\n");
			}
			if (mPassportApply.getName() == null
					|| !mPassportApply.getName().equals(result.getFirstName() + result.getSecondName())) {
				tip.append("名字输入有误！\n");
			}
			if (tip.length() > 0) {
				tip.setLength(tip.length() - 1);
				// 提示tip内容。
				ToastHelper.toast(getContext(), tip.toString());
			} else {
				mPassportApply.setFirstName(result.getFirstName());
				mPassportApply.setSecondName(result.getSecondName());
				Log.i("dbug", "check ok" + mPassportApply.getFirstName() + mPassportApply.getSecondName());
				// 提交表单数据
				new SendDataTask((ILoading) getContext(), true).execute();
			}
		}
	}

	/**
	 * 提交表单，获取cookie、验证码图片、额外参数
	 * 
	 * @author Twinkle
	 * 
	 */
	private class SendDataTask extends SimpleAsyncTask<PassportGoApply, Void, Drawable> {
		public SendDataTask(ILoading loading, boolean showLoading) {
			super(loading, showLoading);
		}

		@Override
		protected Drawable onLoad(PassportGoApply... params) throws Exception {
			return PassportService.sendPassportData(mPassportApply);
		}

		@Override
		protected void onUI(Drawable result) {
			if (result != null) {
				MobclickAgent.onEvent(PassportApp2Activity.this, UmengVar.PASSPORT_SUBMIT_01);
				showValidate(result);
			} else {
				MobclickAgent.onEvent(PassportApp2Activity.this, UmengVar.PASSPORT_SUBMIT_01_F);
				ToastHelper.toast(getContext(), "无法获取验证码，请重试");
			}
		}
	}

	/**
	 * 提交验证码和表单信息
	 * 
	 * @author Twinkle
	 * 
	 */
	private class SendDataAndValidateCode extends SimpleAsyncTask<PassportGoApply, Void, String> {
		public SendDataAndValidateCode(ILoading loading, boolean showLoading) {
			super(loading, showLoading);
		}

		@Override
		protected String onLoad(PassportGoApply... params) throws Exception {
			// String info = "ok";
			// mPassportApply.setSerial("11112222");
			// PassportService.submitPassport(mPassportApply);
			return PassportService.sendDataAndValidateCode(PassportApp2Activity.this, mPassportApply);
			// return info;
		}

		@Override
		protected void onUI(String result) {
			Intent intentConfirm = new Intent(getContext(), PassportAppFinishActivity.class);
			intentConfirm.putExtra("result", result);
			startActivity(intentConfirm);
			finish();
		}

	}

}
